package xxl.robotlegs.extensions.viewmanager.impl 
{
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	/**
	 * ...
	 * @author XXL
	 */
	public class StageCrawler 
	{
		private var _binding:ContainerBinding;
		
		public function StageCrawler(containerBinding:ContainerBinding) 
		{
			_binding = containerBinding;
		}
		
		public function scan(view:DisplayObjectContainer):void
		{
			scanContainer(view);
		}
		
		private function scanContainer(container:DisplayObjectContainer):void
		{
			processView(container);
			const len:int = container.numChildren;
			for (var i:int = 0; i < len; i++) 
			{
				const child:DisplayObject = container.getChildAt(i);
				child is DisplayObjectContainer
					? scanContainer(child as DisplayObjectContainer)
					: processView(child);
			}
		}
		
		private function processView(view:DisplayObject):void
		{
			_binding.handleView(view, view["constructor"]);
		}
		
	}

}